Tweaked code to get it to compile with Java 6