Added Logging Support

Added support for logging and improved overall error handling.