Updated to fix broken code formatting.

Fixed broken code blocks and re-formatted a lot of the code to be more readable and correctly indented.