slight refactoring + fix encoding issue