refactor handler, add some more logs for debugging