PHP functions refactoring