Revised code with better figures