Cleanup and fixes

Code cleanup and fixes