Refactor and fix commands