Tests and optimization