Rewrite, added multi support