refactoring to elegant code