Added trim and factorial functions