algo first step and clean-up