Add test function, fix overflow issue