a bugfix and various improvements