filled with semi pseudo code. not final. added test class.