Put commands into procedures; various other fixes