fixed some routines to pass all the tests