Separated handlers into its own functions.
Cleaned up formatting a little bit