fixed dual purpose function