Code Cleanup

Added comments and resolved some warnings