refactored socket buffer readin