more unit tests, divide by 0 fixes and cleanup