basic version implemented, only optimizes row-column case right now