porting megacoin code