some minor refactoring and joshing errors