Refactor

Accept this when ready or let me know what I should change. A bit more could be refactored, but at this point I feel comfortable working on the next parts.