Indent code and fix minor bug