repaired memory leak, out of bound errors