added the bare minimum required to get factorial to type check and fixed a few type checking and type inferring bugs