Refactor and broke up code pieces