Some bug fixes
Merged Dennis