Cleanup and code fixes