fixing code from SO