Moved delete code to better location