adopted to use with java 6