neat solution without temporary file