Refactor of almost entire codebase.

 * Instead of writing the functions out, I wrote functions that returned
   functions to make the code much more readable.
 * Added a better way to handle 'Access-Control-Allow-Origin'.