Code Cleanup

Performed a lot of code cleanup.