made logic more reusable