refatored for code review