Uncommented endSession(), seems to work now