Splitting your code into subprograms is helpful. You could have one subprogram that defines variables/sprites, one subprogram that runs the game, one that contains subroutines to render the game, etc, and of course the "main" program which sets everything up.