removing recursion loop