Commands

This PR performs some refactorings and builds the infrastructure for undoable commands.