Debug and optimize