Plenty of little fixes + more unit tests