We need a cleaner pattern for this. This code is being copied and pasted a lot :(