replaced a lot of dynamic type casting to improve code completion