Fix nasty bug; Variables moved to central location