added factorials and fixed up functions