Extended bb, moved more code into state, code clean up.