update and some refactoring