Added undefined check in instance transform matrix and wrote unit tests