Improved php code