Reading from the socket + refactoring of corresponding code