Refactor sys globals into an independant library