Cleaned up control code