Changing sort to throw error if invalid