data munging (ruby) part 1,2
some refactoring