added else clause to fix loop