Implemented asynchronous waiting
Code cleanup part 2 (still not finished yet)