PWS-172 #comment Replaced switch with if
PWS-172 #comment replaced callbacks with promises.