Code cleant a bit and added automatic form detection.