Some refractoring, fixed issue with command permissions