Final version, tests added