added another alternative implementation