fixes to improve speed of template constuctor