All the `-1` could be refactored to a constant. Maybe INVALID_ID or similar.