refactored to use promises
fix listener close
fixed closing of the listener and added logging messages