Added debug, legend, direct mode select, bug fixes