Tidy up some code and add move file logic