Security improvements, minor bug fixes