rewrite some code to make make safety more obvious