More code refactored

Most of the jqouery code is refactored.