Encoding IDs

fixes #337