some comments and refactoring for D.R.Y