used jquery deferreds to refactor the code.
added jquery deferred and refactoring
Merge pull request #58 from vman/master

Used jQuery deferred to load the functions