Small fixes in code and tests