These type checkings are weird, maybe use isinstance?