Refactor toMap