changed error handling to callback and minor tweaks as per review