Remove unnecessary function scope
Simplify promise handling
Fix jshint issue