JH - finally was able to merge all of the code