Minor changes

Convert some untyped variables to typed variables, replace custom Sum function with built-in function (in some files, to be done for remaining files).