Quick tidy up of ugly looking function