merged divergent code and adapted it to be in a consistent style