Improved some error messages, fixed sorting bugginess.