Refactor many small items
Refactor more
Refactor first_available_ip lookup.