Refactor custom code method