converted to ARC and modernized code