code refactored / unit tests added