rewrite to simplified and secure code