Total code rewrite