Various bugfixes #1344 Adding fix based on Dennis comment

Various bugfixes #1344