Code cleaned and ported to Java 7