fixing memory leak warning
fixed returning stack allocated block