refactoring, performance improvements, documentation of encryption