Tidyed up stuff
fixed some PHP bugs