improve legalizer decision code