made entity code more generic