code refactoring + upgrade