Cleanup and some security enhancements