Refactored into function, will convert to class later.