timing correction, code clean-up