Bug fix

Squashed a bunch of bugs!