reworked for Java 7