port the cleanup part to the staging plugin