Duplicated code to handle root and regular users