fixes most of the newly failing unit tests and adds better null checking