first draft of maximizing blocks algorithm