Refactor secrets function