Code Cleanup and Fixes