Today my mind got blown

While coding randomly because i was stuck in a starbucks a friend of mine told me i should read the following articles after reviewing my github code. They kinda blew my mind and made me realize i have been doing a clustermess when i write javascript(Node i don’t do it professionally almost ever).First mistake using the top level namespace for all my functions. Thefore he pointed me to the following article which made a pretty deep impact and solved my problem.
http://markdalgleish.com/2011/03/self-executing-anonymous-functions/

Second one was my bit of code could be imported and would work sometimes. He pointed me to this article on writing modular js that honestly points to what im doing from now on.
http://addyosmani.com/writing-modular-js/

Not adding much new here but recommending this as must read.
Will post my code from before and after applying this.