restructuring for easier testing