Moved all existing control code here