I would move this to a function, and add unit-tests :).