Cleaned up template code