Fixed memory leak and changed some members of classes to private