Inheritance not working as it should