inline the mint library directly into the code - rewrite from scratch to be more robust