moved control logic to separate file