Added calibration pattern detection. Removed boilerplate code.