Fix broken unit tests and add new ones