refactor most of control