Queries and ilpcontrol refactored