refactored in order to remove unnecessary casts