Bug fixes

Fixed a variety of bugs and incorrect behavior