Clean up

I have cleaned up the framework of the whole procedure, please check it
out. But remember to back up some of your changes.