Refactored PHP code ! much cleaner now...