add ref cells and make primitives behave polymorphically and some general cleanup