fixed bugs ewout found