refactors. extracts functionality