working version before clean up