impemented preference generation and fixed up state machine