fixing some memory leak and uninitialise variable
switch from key / value as int to key / value as string