added fixes from micbaldur thread