fixing out of bounds erros