Fix for Bug #29736 and some code formatting

Pull request to the Bug #29736 reported by Volkmar Schlothauer

Link: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=29736