methods for encoding