Added a bugfix and some additional debugging.