Fixed some tabbing errors and refactored some code