A few fixes

Found a few security issues and fixed them. Plus a little cleanup here and there.