Some refactoring+comments