fixed a lot of bugs. dropping connection still causes crash and need to implement non blocking read