Replace home rolled solution with a single library that does all of this.
Replace home rolled solution with a single library that does all of this.