Debugged and added test
refactored recursive search