added printf based implementation