merged naor's changes to cup file