rewritten machtmaking code