vjr minor refactoring, bug fixes