Refactor

 * Passing State allows the function take one less argument
Extract function