Improved error handling and added rotating log files.