Removing code duplication when handling shortcuts