Fix minor global vars bugs