refactored some ctrl code