new object-oriented implementation contributed by Matko Adjelinic, lot more debug output (which goes to debug div), configurable index name which is argument to constructor