Updated for 1.2.3.1: Rewrote code for compatibility.