rewrote things to be simpler and take advantage of java 8