Various bug fix

Now it seems to be working.