Redone changes to code after pull from Isidro's code