changed error message and added logging