initialLocation referred to global object instead of function-scoped variable