Partially ported. Removing dependency on tinyclos