Fixed bugs found from unit tests
Updated async version