fixed UI matrix generation function