Remove non-necessary commands and deal with states