Bug fixes. Now passing tests