Test cases and optimizations