Finalised the simulation and improved the code