Move statement compilation to its own method

@GrahamCampbell thanks for your effort and patience.