refactored and added incomplete tests