Refactoring: code clean up and tabbing issues