Replaced code with my code

Added error handling, only thing missing is the XML parsing.
Merge pull request #1 from NinjaTomate/master

Replaced code with my code