Refactoring

Refactor to_array method.