Fixing Endless loop