add encoding detection; switch to OOP instead of static usage