updated code for ios 6 compatibility