added documentation, located serious error (probably some compiler optimization, but unknown how to solve...