some style changes and script adapted for older version of php