using alternative approach without the need of temp buf