huge code refactoring before 1.3 release