refactored using find_all and reduce
refactor recursion and name block variables