reorganized for easier testing