vb/ib bug fixing and refactoring