Refactor

Separated logic into discrete methods.