TWIN: Implement some control code and fix some bugs