cleaned things up a lot by using fold with java lambas.