Got promises to work for getDirections function.
Refactored JavaScript.