Refactored by Enrique.