Reduction of excessive casts and refactoring

There are some slightly refactored methods to have proper names. Also reduces some excessive casts to a single variable