Refactored a lot of underlying runtime magic. Fixes a few bugs - in particular BOOLs are now correctly stored.