Remove code duplication in doubly-linked-list implementation. This isn't any easier to read I swear.