Fixed bugs in template uploading