Code rearrangement due to g++ compiler error