works more or less, slow though and not confident of the simulation
results