Updated source files to the latest prototype

- Replace handlers with controllers
- Fixed a number of issues with the middleware handling
- Replaced logic for environment loading