fixed some replace derp and removed duplicate code