Fixing unit tests and adjusting code