Cleanup code and fix minor indentation errors