Code cleanup.

Replaced some Java 7 code with Java 8 code. Also, the
ElementNameResolver is now called only when needed.