Minor changes made. Stable w/ small bug
Small changes made to error checking etc.
The bug where if you connect many times still exists but I think I know the problem is with the read function.