Made some global functions local (minor performance increase)