fixed undefined behaviour