refactor, smaller functions