lots of refactoring and making it usable by the openhab app