Bug fixes

Fixes bugs from previous diffs that weren't tested before committed.