Bugfix (thx doino1990), code refactorings