Cleaned code for generating figures