sockread: cleanup code and allow arguments