Major refactor and change to make use of Java 8's lambda features.