refactoring and fixes

Hello,
thank you for this tool. I needed it and I thought to make some change.