Fixed various bugs with CUP.