code refactoring
add sorting by click on column titles in template (issue #2)