Sanitized template handling to make it consistent across methods.  Also fixed mismatch between "prependTo/appendTo" methods and "append/prepend" methods.