ADD: rewritten in swift