Some code cleanup

Refactor some repeated commands: call one function now.