Initial tests seem to be successful. Trying to refactor code...