fixed calculating length of data