Made a common error function, fixed a bug in order preservation