refactored. removed infinite recursion