Small code rewrite