I probably should have used a library for this.