Added logic for detecting if online