Some refactor, comments added