Redmine/6589

Fix segfault bug, and clean up the code a bit.
Lol! What was the point in having it in the first place... :-P