Improved traceplot function