Refactored, globals moved to external file.