add templatetags and some improvements on coding style