refactoring + compatibility fixes