added saveRect utility function