fix for potential undefined behaviour