Fix broken/failing tests and implementation