Added template engine. Refactored client-side code