fixing some small bugs and prettifying codes
Rewriting javascript code and use object oriented