changed logic again, because the old logic was buggy