getting memory error.  will defactor for simplicity