Fixing bugds to make tests pass