More code changes

Lots of additions and type casting changes to the code.