refactoring code to follow nodejs callback pattern issue: #18