Deans refactoring

Simulation code refactored into classes. Final version under code folder.