Added $JAVA_HOME. Changed some code a bit