Moved csbi code into a function.