Completed recursive lookup algorithm implementation. Not tested though.