refactored some code, removed the dependency of jQuery