refactoring, at last finally fixed #17