extensive code rewrite, changing version to 2.x