While this is technically correct:
if (received != 10) // Terminate if newline char detected
you're better off writing
if (received != '\n')
Much of embedded electronics assumes ASCII encoding, and this is no exception, but you're still better off using the symbol instead of the code.
You loop while serial I/O is ...