merge refactoring from xabolcs/nightlytt