some refactoring. minor fixes