refactored using resizing arrays and hashtables