error messages and fixing sorting