Initial fork from phreekz.de with fix