Debug and optimization tweaks