Refactored code, split into multiple files, most functions converted to object methods