init
changed a in place method
simpler code
use single function for recursion