Refactor of maintenance command to be more optimal