Cleanup

Cleaned up many warnings and added comments.