refactored code added many test