Removed global variables, encapsulate functions into objects