raw PHP code, needs a brush-up