Optimized by checking preconditions using recursion