Add magic encoding
Rubocop and fixes