replace cast to function