Edited for php compatibility