Removed code duplication.

- Multiple small changes.