Reverted last change 4e6ca9e257030a4d949735665348e3d02937b5f2 due to unacceptable side effects, and implemented a different approach to try and fix issue #18