Fix path to template-library-core

Also return to previous directory when complete.
This should enable the versions to be correctly updated.
Fix incorrect loop placement

This was probably caused by not paying enough attention when resolving conflicts earlier.