Rebased everything with David's code