Some cleanup and fix for issue 131