Adding bugfixes by CDeLorme