Fix some little code mistakes

Hi,

Following this articles I got some troubles having all the things working so I made all needed changes to get all working.

See commit messages for more explanation.