Template fixes

Fixed #992 and (partly) 909.