debug and optimize