added several comments, made refactoring