current code finally refactored.