solved weird if loop problem