little refactoring
rewrite with jquery deferred object