Added a bit more logging code to give a better idea of what happened in case something goes wrong.