fixed messages.length error