tidy up visit code