fix undefined behavior (#2)