[fix] Change the way inheritance is done to combat memory leaks