Is there not a way to reuse the same code? Seems like it wouldn't be too hard to cut this code down in nearly half.