Refactored promises and better error catching