There's a lot of copy-pasta code here. Please merge it.