replace compact function