Added error capturing.