Added error logging