Buffer overflow fixes