Code update and some fixes.
Merge pull request #1 from Dansuf/master

Changes for a better working port.