Some misc cleanup and tweaking of functionality