First Final Version

Working for all the tested cases.