rearranged code and added decls for template specializations