Changed things a bit

Added error handling and logging.
Added file numbering.