names changed and minor refactoring