Fixed bugs and TESTED.