added channel closing & improved write & its test