Reworked and updated to support iOS8.

Reworked to remove redundant code and improve memory management.