cleanup, tests and Prepare optimization