Corrected implementation of fact