Updated with modifications from @seattle