Refactoring codes to use BasicHandler