3.0 code rewritten