fixed the valid checking, and made extra 0s only if invalid