Fix goroutine leak and style issues