Fixed invalid memory read (thanks to valgrind).