convert loop to recursion
remove duplication around returning 0
remove unnecessary conditional