total refactor to greatly simplify and get iOS8 support