template + little optimization