replace needs fixing but no segfaults