small refactor

Small refactor - made code slightly easier to read and removed some duplication.