Simplified cleanup code, added in trash function.