refactored a bit to automate testing of simple cases - ensuring working algorithm while doing performance improvement for the big problem set