Fix a couple of bugs found by tests :D