Slight restructure of handler function to move get/post logic out
Cleaned up handle_hook function, removed a lot of nesting and made it neater