Updated for compatibility with Java 6