Refactor top command