Large code rewrite, and added proper working support.