adding some changes to integrating from kalm.m