refactored some old php code