Finish simplify function
Tidy up the file