rewrite with parse loop and read loops decoupled.