Fixed all tests and various bugs that appeared during that process.