few code fixes and cleanup