Fixed the bugs up to casting throws.