big cleanup, implemented proper templating.