Changed inverse function and fixed type where n was being used instead of phi in inverse function.