Removed globals and renamed vars for readability