Rewrite some tests, add more comments in the code