rewrite + more tests