Added logging support and made improvements.