removing dependency on ion by copying the necessary code