fix a bug in deciding template size