wrote compact function