Major error fixed when closing the software.
Also cleaned up the RGB calculate sequence.
Colors are now calculated in the right order.