using instanceof to check if primitive; inelegant but works