use selection instead of xsel command
fix some file descriptor leakage bugs