full code including pretty figures