Clean up visited type (unneeded). Move some functions around