Refactoring PHP Application