There should probably be an instanceof check here to be 100% correct.