Optimalization from https://github.com/foosel/OctoPrint/pull/206