Rewrote the path management since the old implementation contained errors.