bugfix and simplification (+optimization)

thought you might take these changes into consideration.

Cheerfully,

Már