refactoring following code audit