removed sorted function to ensure proper sorting