Cleaned up code, removed globals namespace