Fixed a lot of bugs + added promises in some places of the functions.