Fixed attribute pointers and cleanup
Cleanup elementbuffer before exit.