finished binary recrusion version