Version 2.00: fully rewritten
Version 2.01: code cosmetics and fixes