Fixing some small bugs and passing tests