Adding encoding, it needs refactorization