Fixing tests and bugs revealed by tests :)