Clean up secure, fix some bugs