fix Gunnar's issue 3 and part of 4