some refactorings
use to_h to get a hash from a struct