refactors and adds a clear command;