fixed maximum recursion depth exceeded error