Refactor to resolve some PHPMD errors/warnings