Support user defined functions

Fixes #17.
Holy shit this is a huge commit.