Re-factored and added support for primitives.