Improve cast usage #539