Code cleanup

-Rearranged variables
-Applied some consistent formatting
-Added some documentation
-Added SIGTERM Handler (CTRL-C)