basic counting and recreating matrix. No tree yet