Try to compact your code. Maybe repeated code can be a subroutine etc.

Also if you use flags, then declare them as BIT and not as BYTE or even worse as WORD.

If you need a BYTE variable, do not declare as WORD.

Ioannis