Bug Fixes

Bug Fixes to various functions