Tests and optimizations