unit tests and optimizations