Second Commit, cleanup and optimizations.