More model optimizations, adding unit tests