Save last state and restore after a power loss

As requested by probonopd in Issue #2.
The updated code should now be able to save and return to it's previous
running state even at a power falure. Please notice that the code isn't
tested though!