Templates and JS slightly refactored