Code cleanup after bugfix for #3

This version works for me without known bugs.