corrected fix for 64bit warning
performance optimization: reducing the number of dynamic casts