Functions and scoping

Functions and scoping have been added.