adding fixes from thomas_adam. Thanks :)