Code: Reduces block nesting

* Reduces block nesting & other minor improvements.
* Using `XDocument` for writing in sprite.