some refactoring
fixed merge conflicts