Rename setup, apply and teardown to before, process_key and after. Add docstrings and check return values from process_key.