Lots of refactoring, added map functionality, started using promises and deferred for the js part