fixed a bug with double entries, many small improvements