refactored and function tests implemented