verify x is not negative
fix to use modulo