[tidy] cleaning the code from leftovers
[fix] fixed memory leak and an invalid access