refactoring of code. minor fixes