There should be a better way than using `asInstanceOf`, what do you think?