Fixed bugs with globals