Added a missing sudo command usage and extracted the conditional in a method