Fix for failing tests & a few bugs