add controls and some refactoring