clean up html and improve sorting