psudo code for contact flattener