Added clear command and cleaned up some code