Various cleanup and fixes