Proper PR for issue #563

I figured I'd take the code from the above issue, and format then submit the changes within into a proper PR.