various refactoring, changes to work on debian