Added functionallity from many forks. Major bug fixes