rewritten script for visualization - easier code