added bounding boxes and fixed matrix shifts