Fixed a set of bugs; rudimentary simulation now works.