A lot of copy/pasta common code here. Shouldn't inheritance be used?