Added automatic contour selection. Improved error messaging.