Refactor: move code into private methods
Change: move this up

 * tried to avoid the second loop
 * didn't understand yet what it did exactly