stole initial bits from github/darius/versecop