minor optimizations, profiling and comment updates
added matrix path recording