Cleaned up JS to include very basic templating