Moved out the impure part.