Added error messages, improved logging