refactor for better code re-use