fixed misplaced error messages