Code Cleanup, and Bug Fixes