Refactor command + add general undo

There might be some issues with drag and drop.