Updated code for instances and elements. Improved performance and internal structure. Added new code for element creation.