Not easy to say without seeing your code but here's my two cents......

In the FAQ there is this thread. http://www.picbasic.co.uk/forum/showthread.php?t=545 .

Move similar codeblocks into subroutines.