refined figure generating code