Some bug fixes

Tests still fail!