fix undefined behavior