Fix a number of compile issues
Add support for typesafe references
Additional improvements