fixes #365 - but finally, not object-oriented