added some comments and refactored the code some more to work better with async calls