fix nil pointer in template, add spec to ensure it won't happen again