Extract function

Would like to make it easier to test, and add something like
http://blog.fallingsnow.net/2009/11/29/helpful-syntax-errors/