Refine the code to fix for Java 6