added sorting functionality