Added error capturing