Adding escape from callback hell and minor refactoring.