Tidy up logic