Fixed logging.
Added error handling.
Fixed 'use lib'.