Big pull request

Includes JR's code because I pulled it locally to make a small fix.