amended to fix nil error