Misc Refactorings & fixes

Resolves: http://bugs.web2project.net/view.php?id=1233