fixing leaking memory from map