Tidy up old code
Maybe add helper functions?