Fixed wrong logic in template