Improve API replacing type with cast