Removing AsInstanceOf and Pattern.Match where it makes sense