Fixes #293

Fixes #293: Improved code organization, improved type safety of variables, and improved coercion of variable values into types with given expressions. Added test suite for coercion to cover common cases.