Extract duplicates into separate functions.

Seems, it will be clean and better :)