refactored with utility functions