Dead code removal and other fixes for Java