got first working version, still need to be optimalized:
too many unneccessary transposes