added destroy funtion and removed redundancy