Bug fixes, add destroy function