Moved trim method to error function