Fixed memory leaks
Added comments and fixed memory leaks
Modified initialization of arrays