moved entire approximation logic from OOP to functional solution