reuseable replace function instead of multiple ones