begin a bit of refactoring
move to separate function