little code refactor + add charset option