Incremental improvements

Broke out the main file transfer code into a seperate function for
improved readability.

Improved logging and exception capturing.