Added function for calculating number of factors