#171. Need to make more robust and unit test, but the concept is in there