Some minor fixes and code cleanup