Rewrite code using less lines