refactoring

moved logic into private methods