refactoring of code - methods introduced (still more refactoring needed)