Added functionality test with minor refactoring