rest of the homework, and sorted it