Another bugfix and some code streamlining.