Made script work correctly over ssh