Various debugging and optimization