Remove debug code
Rewrite to use promises