clean copy of brutuscat's fixes