Fix #3242 and some code cleanup:

- Only explode '/' and set address_subnet when address is a subnet, it
  fixes issue reported at #3242
- While I'm here, do some cleanup on the way addresses are treated
  - Remove unecessary variable $tracker, we already have $counter set
    with the same value
  - Use if:endif and while:endwhile where there is html block inside the
    block
  - Use more meaning names for variables instead of item, item2, item3
    and item4
  - Use while($counter <= $count()) instead of using foreach referencing
    array using $counter inside