Contributed by exedor:
http://forum.arduino.cc/index.php?topic=146947.msg1282508#msg1282508