Fixed failing tests and global memery leak error