Updated with global variables