Add length check (stab at avoiding freezes - may have to go to char[] buffers :/)