adding cast and making code consistent in two places