Hopefully fixing some issues brought to my attent

ion by the original author of this sourcecode