Fix some random memory overflow issues