refactored various handler functions