Fix some issues with 64c7a418b8f35f8badca143b42d407b8c38c0c31

thanks @gamedevsam