added another implementation for maxpain calculation