Added profiling

* added headers
* moved some code out of handlers to make it a bit less crowded.