Implement a memory for the controller (accesible via mem.) and cleanup code