Code cleanup and merge with master