ported to scala 2.11, beautified according to stylecheck