Invalid reads reported by valgrind in replaceFrame fixed