added defensive code into trendy around last set bit