fix for encoding issue with forms with an encoding declaration

and a tiny refactor