code fixes and cleanup