code refactoring + comments