Added function for calculating n