refactored solution

removed unused variables and functions
grouped code into self calling closures to prevent pollution of global
namespace
Merge pull request #1 from MovGP0/master

refactored solution