Make the elapsed time calculation somewhat more robust by not only counting seconds but also minutes and hours.
Make the new document xquery template valid so that you do not get the error message in your face immediately.