Fixed output selection and cleanup the code. We need to adjust the order a bit still.