Fix: nil pointer reference in goroutine; cleaned up code to make
references clearer