fix handler promise and added unit tests