Fixed bugs.

Hi,

I fixed two bugs in the code. At least they were causing problem for me. If you think this change is useful you can pull.

Regards,