Optimized the code

The code has been optimized through adjusting it the the new "flat" way
of saving data.