code cleanup and security, lib cleanup