Fixed most indentations and refactored some code from controllers