Switched to async logic flow.
Added some context to some of the functions via a comment.