Tidy up
wasn't happy with this function