Organised code and added sampler