Minor enhancements
Avoiding count_nonzero
major bug fixes and enhancements
Code restore after serious issue