bug fixes with sort