Fixed bug in deferred.then, added tests that caught the bug :)