Shelly optimalizations

@gotar could you take a look? it should work ;)