complete rewrite for ios 7