fix trailing number calculation