clean up and refactor autoplot code