Merged with Rafael's changes