Abstracting suplicated code

See #22