Refactoring PHP code and introduced building table