cleaned code, and fixed global namespace pollution