split up logic a bit