Refactor of short code function